package cn.lingyangwl.agile.msg.push.controller;

import cn.lingyangwl.agile.msg.push.assembly.*;
import cn.lingyangwl.agile.msg.push.model.entity.*;
import cn.lingyangwl.agile.msg.push.model.rqrs.notice.*;
import cn.lingyangwl.agile.msg.push.service.*;
import cn.lingyangwl.agile.ram.*;
import cn.lingyangwl.framework.core.response.*;
import cn.lingyangwl.framework.data.mate.annotations.*;
import cn.lingyangwl.framework.validation.group.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 消息模板
 * @author shenguangyang
 */
@Api(tags = "消息模板")
@RestController
@RequestMapping("/msgNotice")
public class MsgNoticeController {
    @Resource
    private MsgNoticeService msgNoticeService;
    @Resource
    private MsgNoticeAssembly msgNoticeAssembly;

    @ApiOperation(value = "分页消息通知")
    @GetMapping("/page")
    @RamResource(action = "msg:msgNotice:query", name = "查询消息模板", type = ActionType.READ)
    public Resp<List<MsgNoticeResp>> listNotice(@Validated MsgNoticeQueryReq req) {
        return Resp.ok(msgNoticeService.listNotice(req));
    }

    @ApiOperation(value = "通过id查找消息通知")
    @GetMapping("/get")
    @RamResource(action = "msg:msgNotice:query", name = "查询消息模板", type = ActionType.READ)
    @FieldBindHandle
    public Resp<MsgNoticeResp> getNotice(@RequestParam(value = "id") Long id) {
        MsgNotice resp = msgNoticeService.getNotice(id);
        return Resp.ok(msgNoticeAssembly.toMsgNoticeResp(resp));
    }
  
    @ApiOperation(value = "保存消息通知")
    @PostMapping("/save")
    @RamResource(action = "msg:msgNotice:save", name = "保存消息通知", type = ActionType.WRITE)
    public Resp<?> saveNotice(@Validated @RequestBody MsgNoticeSaveReq req) {
        return Resp.ok(msgNoticeService.saveNotice(req));
    }
  
    @ApiOperation(value = "更新消息通知")
    @PostMapping("/update")
    @RamResource(action = "msg:msgNotice:update", name = "更新消息通知", type = ActionType.WRITE)
    public Resp<?> updateNotice(@Validated(UpdateGroup.class) @RequestBody MsgNoticeSaveReq req) {
        return Resp.ok(msgNoticeService.updateNotice(req));
    }

    @ApiOperation(value = "更新消息通知状态")
    @PostMapping("/updateStatus")
    @RamResource(action = "msg:msgNotice:updateStatus", name = "更新消息通知状态", type = ActionType.WRITE)
    public Resp<?> updateStatus(@RequestParam(value = "status") Boolean status,
                                        @RequestParam("id") Long id) {
        msgNoticeService.updateStatus(id, status);
        return Resp.ok();
    }
  
    @ApiOperation(value = "批量删除消息通知")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "msg:msgNotice:delete", name = "删除消息通知", type = ActionType.WRITE)
    public Resp<?> batchDeleteNotice(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(msgNoticeService.batchDeleteNotice(ids));
    }
  
    @ApiOperation(value = "删除消息模板")
    @DeleteMapping("/delete")
    @RamResource(action = "msg:msgNotice:delete", name = "删除消息通知", type = ActionType.WRITE)
    public Resp<?> deleteNotice(@RequestParam(value = "id") Long id) {
        return Resp.ok(msgNoticeService.deleteNotice(id));
    }
}
